package com.ceshiren.hogwarts.framework;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Stream;


public class ParamsTest {
    /*@ParameterizedTest
    @MethodSource("stringProvider")
    void testWithExplicitLocalMethodSource(String argument) {
        assertNotNull(argument);
    }

    static Stream<String> stringProvider() {
        return Stream.of("apple", "banana");
    }*/

    @ParameterizedTest
//    @ValueSource(strings = {"selenium","apple"})
    @MethodSource
    void search(TestCase testCase) throws Exception{
        /*WebDriver webDriver = new ChromeDriver();
        webDriver.get("https://ceshiren.com");
        webDriver.findElement(By.cssSelector("#search-button")).click();
        webDriver.findElement(By.cssSelector("#search-term")).sendKeys(name);*/
        testCase.run();
    }

    static Stream<TestCase> search() throws Exception{
//        return Stream.of("apple","orange");
        ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
//        TypeReference typeReference = new TypeReference<List<String>>(){};
        TestCase testCase = mapper.readValue(new File("src/test/resources/framework/search.yaml"),TestCase.class);
        return Stream.of(testCase);
    }
}
